import { Queue } from "./04_数组实现队列结构";

function laseRemaining(n: number, m: number) {
  const queue = new Queue<number>();
  for (let i = 0; i < n; i++) {
    queue.enqueue(i);
  }

  while (queue.size > 1) {
    for (let i = 0; i < m - 1; i++) {
      queue.enqueue(queue.dequeue()!);
    }
    queue.dequeue();
  }
  return queue.dequeue()!;
}

console.log(laseRemaining(5, 3));
console.log(laseRemaining(10, 17));
